/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reportcenter.componentbinder.list;

import java.util.Map;
import javax.swing.JComboBox;
import org.springframework.beans.support.PropertyComparator;
import org.springframework.binding.form.FormModel;
import org.springframework.binding.value.ValueModel;
import org.springframework.richclient.form.binding.Binding;
import org.springframework.richclient.form.binding.swing.ComboBoxBinder;
import org.springframework.richclient.list.BeanPropertyValueListRenderer;

/**
 *
 * @author renan_luz
 */
public class CustomBinder extends org.springframework.richclient.form.binding.swing.SwingBindingFactory {

    /**
     * @param arg0
     */
    public CustomBinder(FormModel arg0) {
        super(arg0);
    // TODO Auto-generated constructor stub
    }

    public Binding createBoundComboBox(String formProperty, ValueModel selectableItemsHolder, String renderedProperty, Object emptySelectionObject) {
        Map context = createContext(ComboBoxBinder.SELECTABLE_ITEMS_KEY, selectableItemsHolder);
        context.put(ComboBoxBinder.EMPTY_SELECTION_VALUE, emptySelectionObject);
        context.put(ComboBoxBinder.RENDERER_KEY, new BeanPropertyValueListRenderer(renderedProperty));
        context.put(ComboBoxBinder.EDITOR_KEY, new BeanPropertyEditorClosure(renderedProperty));
        context.put(ComboBoxBinder.COMPARATOR_KEY, new PropertyComparator(renderedProperty, true, false));
        return createBinding(JComboBox.class, formProperty, context);
    }
}
